package com.itheima.redbaby.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;


public class StreamToString {
		
		//从流里获取文本
		public static String getTextFromStream(InputStream is){
			byte[] b = new byte[1024];
			int len;
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			try {
				while((len = is.read(b)) != -1){
					bos.write(b, 0, len);
				}
				//把字节数组输出流的内容转换成字节数组，然后用这个字节数组构造一个字符串
				String text = new String(bos.toByteArray());
				return text;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return null;
			
		}

}
